// 获取DOM元素
const imgEl = document.querySelector("img") // HTMLImageElement | null

if (imgEl !== null) {// 类型缩小
  imgEl.src = "xxx"
  imgEl.alt = "yyy"
}

const img1El = document.querySelector(".img") // Element | null
const img2El = document.querySelector(".img") as HTMLImageElement // HTMLImageElement

img2El.src = "xxx"
img2El.alt = "yyy"


// 类型断言的规则:断言只能断言成更加具体的类型,或者 不太具体 类型
const age: number = 18

// const age2 = age as string // 错误的做法

// TS类型检测来说是正确的,但是这个代码本身不太正确
const age3 = age as any
const age4 = age3 as string
console.log(age4.split(" "))

export { }